package top.iuna.jxls.simpledemo;

import java.util.HashMap;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import lombok.Getter;
import lombok.Setter;
import top.iuna.jxls.core.service.PaddlerRankingService;
import top.iuna.jxls.core.view.SimpleJxlsView;


/**
 * Simple demo of Spring View with Jxls downloads files.
 * 
 * @author Cheney.Sun
 * @time 2018-04-07
 */

@Getter
@Setter
@Controller
@RequestMapping("/paddlerRanking")
public class SimpleDemoController {

  @Resource
  private PaddlerRankingService paddlerRankingService;

  private final String templateFilePath = "templates/simple-demo-001.xlsx";
  private final String targetFileName = "国际乒联2018年4月世界排名";

  @GetMapping("/demo0")
  public ModelAndView downloadDemo0() {
    HashMap<String, Object> dataMap = new HashMap<>();

    // 数据引用地址
    dataMap.put("dataRefer", "https://cn.ittf.com/worldranking/");

    // 男子世界排名数据
    dataMap.put("menRankingList", paddlerRankingService.getMenRankingList());
    // 女子世界排名数据
    dataMap.put("womenRankingList", paddlerRankingService.getWomenRankingList());
    // 30条AI数据
    dataMap.put("aiPaddlers", paddlerRankingService.newAIPaddlers(30));

    return new ModelAndView(new SimpleJxlsView(templateFilePath, targetFileName), dataMap);
  }

}
